#include "viml/memory_optimizer.h"

namespace viml {

// GlobalMemoryOptimizer实现
std::unique_ptr<MemoryOptimizer> GlobalMemoryOptimizer::instance_;
std::mutex GlobalMemoryOptimizer::instance_mutex_;
bool GlobalMemoryOptimizer::initialized_ = false;

MemoryOptimizer& GlobalMemoryOptimizer::get_instance() {
    std::lock_guard<std::mutex> lock(instance_mutex_);
    if (!instance_) {
        instance_ = std::make_unique<MemoryOptimizer>();
        initialized_ = true;
    }
    return *instance_;
}

void GlobalMemoryOptimizer::initialize() {
    std::lock_guard<std::mutex> lock(instance_mutex_);
    if (!instance_) {
        instance_ = std::make_unique<MemoryOptimizer>();
        initialized_ = true;
    }
}

void GlobalMemoryOptimizer::shutdown() {
    std::lock_guard<std::mutex> lock(instance_mutex_);
    if (instance_) {
        instance_->clear();
        instance_.reset();
        initialized_ = false;
    }
}

bool GlobalMemoryOptimizer::is_initialized() {
    std::lock_guard<std::mutex> lock(instance_mutex_);
    return initialized_;
}

} // namespace viml